import React, { Component } from 'react';
import './index.css';

export default class index extends Component {
  handleCheck = (ev) => {
    this.props.updateAllItem(ev.target.checked);
  };

  render() {
    let { list } = this.props;

    let total = list.length;
    let doneCount = list.filter((item) => item.done === true).length;
    return (
      <div className="todo-footer">
        <label>
          <input
            type="checkbox"
            checked={doneCount === total && total >= 1}
            onChange={this.handleCheck}
          />
        </label>
        <span>
          <span>已完成{doneCount}</span> / 全部{total}
        </span>
        <button
          className="btn btn-danger"
          onClick={() => {
            this.props.clearAllItem();
          }}
        >
          清除已完成任务
        </button>
      </div>
    );
  }
}
